﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System.Threading.Tasks;
using Zocono.WCS.Admin.Models.User;
using Zocono.WCS.Application.AppLogManage;
using Zocono.WCS.Application.AppTraces;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Admin.Controllers.LogMoudle
{
    public class InterfaceLogController : BaseController
    {
        private readonly LogApp _LogApp;

        public InterfaceLogController(LogApp logApp,IMemoryCache memoryCache, TracesApp tracesApp, IHttpContextAccessor httpContextAccessor) : base(memoryCache, tracesApp, httpContextAccessor)
        {
            _LogApp= logApp;
        }

        public IActionResult Index()
        {
            return View();
        }
        public async Task<ActionResult> InterfaceLogAsync()
        {
            InterfaceLogInfoDto interfaceLog = new InterfaceLogInfoDto();
            var res = await _LogApp.GetIterfaceLogInfoAsync(interfaceLog);
            return View(res);
        }

        /// <summary>
        /// 获取接口日志列表
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> GetInterfaceLogInfoAsync()
        {
            InterfaceLogInfoDto interfaceLog = new InterfaceLogInfoDto();
            interfaceLog.PageIndex = (Start / Length) + 1;
            interfaceLog.PageSize = Length;
            var description = Request.Form["Description"].ToString();
            var interfaceUrl = Request.Form["InterfaceUrl"].ToString();
            var interfacePara = Request.Form["InterfacePara"].ToString();
            var interfaceResult = Request.Form["InterfaceResult"].ToString();
            interfaceLog.Description = description;
            interfaceLog.InterfaceUrl = interfaceUrl;
            interfaceLog.InterfacePara = interfacePara;
            interfaceLog.InterfaceResult = interfaceResult;
            interfaceLog.start = Request.Form["startTime"];
            interfaceLog.end = Request.Form["endTime"];
            var res = await _LogApp.GetIterfaceLogInfoAsync(interfaceLog);
            var pageData = new TableData<InterfaceLogInfoDto>(Draw, res.Total, res.Total, res.Result);
            return Json(pageData);
        }
    }
}
